// https://leetcode-cn.com/problems/merge-two-binary-trees/
// 617. 合并二叉树
// 给你两棵二叉树 root1 和 root2。返回合并后的二叉树。

import { TreeNode } from '../utils/index.ts';
function mergeTrees(
    root1: TreeNode | null,
    root2: TreeNode | null
): TreeNode | null {
    if (root1 === null) return root2;
    if (root2 === null) return root1;

    const mergedRoot = new TreeNode(root1.val + root2.val);
    mergedRoot.left = mergeTrees(root1.left, root2.left);
    mergedRoot.right = mergeTrees(root1.right, root2.right);
    return mergedRoot;
}
